﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using KVB.Common;


namespace Customer_Profile.eCard.DBDao
{
    public class AttachDao
    {
        public static bool AddAttach(int deal_no,                                    
                                    string view_name,
                                    string attach_name,
                                    string attach_type,
                                    string attach_size,
                                    string attach_url,
                                    string business_type)          //添加一个卡账记录
        {
            SqlConnection conn = null;
            try
            {              
                DB.Connection(ref conn);
                SqlParameter[] parameters ={ new SqlParameter("@deal_no ", SqlDbType.Int),
                                             new SqlParameter("@view_name ",SqlDbType.VarChar,250),
                                             new SqlParameter("@attach_name ",SqlDbType.VarChar,250),
                                             new SqlParameter("@attach_type ",SqlDbType.VarChar,250),
                                             new SqlParameter("@attach_size ",SqlDbType.VarChar,250),
                                             new SqlParameter("@attach_url ",SqlDbType.VarChar,250),
                                             new SqlParameter("@business_type ",SqlDbType.VarChar,20)
                                           };
                parameters[0].Value = deal_no;
                parameters[1].Value = view_name;
                parameters[2].Value = attach_name;
                parameters[3].Value = attach_type;
                parameters[4].Value = attach_size;
                parameters[5].Value = attach_url;
                parameters[6].Value = business_type;
                DB.ExecuteNonQuery(conn, CommandType.StoredProcedure, "eCard_attach_insert", parameters);
                return true;
            }
            catch (Exception e)
            {
                KVB.Common.Log.WriteDefaultLog("AttachDao.AddAttach", e.Message);
                return false;
            }
            finally
            {
                DB.ConnDispose(ref conn);
            }
        }

        public static DataSet getAttachList(int deal_no,string business_type)          //查询附件列表
        {
            DataSet ds = null;
            SqlConnection conn = null;
            try
            {
                DB.Connection(ref conn);
                SqlParameter[] parameters ={ 
                                               new SqlParameter("@deal_no", SqlDbType.Int),
                                               new SqlParameter("@business_type", SqlDbType.VarChar,50)
                                           };
                parameters[0].Value = deal_no;
                parameters[1].Value = business_type;
                ds = DB.ExecuteDataset(conn, CommandType.StoredProcedure, "eCard_attach_list", parameters);
                
            }
            catch (Exception e)
            {
                KVB.Common.Log.WriteDefaultLog("AttachDao.AddAttach", e.Message);                
            }
            finally
            {
                DB.ConnDispose(ref conn);
            }
            return ds;
        }

        public static bool DeleteAttach(int attachid)          //删除一个附件
        {
            SqlConnection conn = null;
            try
            {
                DB.Connection(ref conn);
                SqlParameter[] parameters = { new SqlParameter("@attach_id ", SqlDbType.Int) };
                parameters[0].Value = attachid;                
                DB.ExecuteNonQuery(conn, CommandType.StoredProcedure, "eCard_attach_delete", parameters);
                return true;
            }
            catch (Exception e)
            {
                KVB.Common.Log.WriteDefaultLog("AttachDao.DeleteAttach", e.Message);
                return false;
            }
            finally
            {
                DB.ConnDispose(ref conn);
            }
        }
    }
}